#include <stdio.h>
#include <string.h>

#define TEST_FILE_NAME "16_Test.txt"

int main(int argc, char const *argv[])
{
    FILE *fp = fopen(TEST_FILE_NAME, "w");
    if( NULL == fp )
    {
        printf("Fail to open file \n");
        return -1;
    }

 
    int iNum = 100;
    float fNum = 123.4;

    // Total 3 strings are written in the file
    fprintf(fp, "~~~~~~Start of fprintf~~~~~~\n");
    fprintf(fp,"iNum = %d, fNum = %f \n", iNum, fNum);
    fprintf(fp, "~~~~~~End of fprintf~~~~~~\n");
    fclose(fp);

    // Only the last string is written into the strBuff
    char strBuff[200] = {0};
    sprintf(strBuff, "~~~~~~Start of sprintf~~~~~~\niNum = %d, fNum = %f \n~~~~~~End of sprintf~~~~~~\n",
            iNum, fNum);
    puts(strBuff);

    return 0;
}


/*

函数 fprintf
    向文本文件写入格式化文本信息

函数 sprintf
    向字符串写入格式化文本信息

在熟练应用函数 printf 的基础上, 使用这两个函数

*/